﻿using DevExpress.Data.Filtering;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.ConditionalAppearance;
using DevExpress.ExpressApp.DC;
using DevExpress.ExpressApp.Model;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.Validation;
using DevExpress.Xpo;
using HC.XAP.FileSystemData.BusinessObjects;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace HC.XAP.FileUpload.Module.BusinessObjects.FileUpload
{
    [NavigationItem("文件管理")]
    [XafDefaultProperty("FileName")]
    [DefaultClassOptions]
    [ImageName("ChangeLabel")]
    //[DefaultProperty("DisplayMemberNameForLookupEditorsOfThisType")]
    //[DefaultListViewOptions(MasterDetailMode.ListViewOnly, false, NewItemRowPosition.None)]
    [Appearance("设置不允许新增", AppearanceItemType = "Action", Enabled = false, TargetItems = "New", Context = "Any")]
    [Persistent("t_FileUpload"), XafDisplayName("文件清单")]
    // Specify more UI options using a declarative approach (https://documentation.devexpress.com/#eXpressAppFramework/CustomDocument112701).
    public class HCOBFileUpload : BaseObject
    { // Inherit from a different class to provide a custom primary key, concurrency and deletion behavior, etc. (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument113146.aspx).
        // Use CodeRush to create XPO classes and properties with a few keystrokes.
        // https://docs.devexpress.com/CodeRushForRoslyn/118557
        public HCOBFileUpload(Session session)
            : base(session)
        {
        }
        public override void AfterConstruction()
        {
            base.AfterConstruction();
            // Place your initialization code here (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument112834.aspx).
        }

        protected override void OnDeleted()
        {
            base.OnDeleted();
            //删除数据时，把磁盘上的文件也一起删除
            try
            {
                File.Delete(this.SystemStoreFile.RealFileName);
            }
            catch //(DirectoryNotFoundException exc)
            {
                //throw new UserFriendlyException(exc);
            }
        }

        [DevExpress.Xpo.DisplayName("文件")]
        [ModelDefault("AllowEdit", "false")]
        //[DevExpress.Xpo.Aggregated, ExpandObjectMembers(ExpandObjectMembers.Never), ImmediatePostData]
        public FileSystemStoreObject SystemStoreFile
        {
            get { return GetPropertyValue<FileSystemStoreObject>("SystemStoreFile"); }
            set { SetPropertyValue<FileSystemStoreObject>("SystemStoreFile", value); }
        }

        [ModelDefault("DisplayFormat", "yyyy-MM-dd HH:mm:ss")]
        [DevExpress.Xpo.DisplayName("上传时间")]
        public DateTime UpLoadDate
        {
            get { return GetPropertyValue<DateTime>("UpLoadDate"); }
            set { SetPropertyValue("UpLoadDate", value); }
        }
    }
}